package com.ts.proj.controller;

import com.ts.base.controller.BaseController;
import com.ts.proj.entity.MarketEntity;
import com.ts.proj.entity.ProjectEntity;
import com.ts.proj.entity.SystemConstantEntity;
import com.ts.proj.json.SystemConstantJson;
import com.ts.proj.service.MarketService;
import com.ts.proj.service.ProjectService;
import com.ts.util.JurisdictionUtil;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

//说明 字符串：Test，作为替换字符串

@Controller
public class MarketController extends BaseController {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private MarketService marketService;

    @Autowired
    private SystemConstantJson systemConstantJson;


    @RequestMapping("/project-market/{id}")
    public ModelAndView projectContract(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            ProjectEntity byId = projectService.findById(id);
            modelAndView.addObject("id", id);
            modelAndView.addObject("byId", byId);
            viewName = "business/touhou/market-list";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-market-add/{id}")
    public ModelAndView projectMarketAdd(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            modelAndView.addObject("proId", id);
            modelAndView.addObject("localId", -1);

            List<SystemConstantEntity> pageList = (List<SystemConstantEntity>) systemConstantJson.constantsByType("project_market_target");
            if(pageList != null && pageList.size()>0) {
                modelAndView.addObject("marketTargetList", pageList);
            }
            viewName = "business/market/market-add";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-market-edit/{id}")
    public ModelAndView projectMarketAddEdit(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            MarketEntity marketEntity = marketService.findById(id);
            modelAndView.addObject("proId", marketEntity.getProId());
            modelAndView.addObject("localId", id);
            List<SystemConstantEntity> pageList = (List<SystemConstantEntity>) systemConstantJson.constantsByType("project_market_target");
            if(pageList != null && pageList.size()>0) {
                modelAndView.addObject("marketTargetList", pageList);
            }
            modelAndView.addObject("marketEntity",marketEntity);
            viewName = "business/market/market-add";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }
}